package TestThread;

public class demo7 {
    public static int count = 0;
    private final static Object locker = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            synchronized (locker) {
            for (int i = 0; i < 50000; i++) {
                    count++;
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            synchronized (locker) {
            for (int i = 0; i < 50000; i++) {
                    count++;
                }
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println("count = "+count);
    }
}
